package com.ruoyi.portal.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.portal.domain.PorConsulting;
import com.ruoyi.portal.service.IPorConsultingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 预约咨询Controller
 *
 * @author cjie
 * @date 2021-06-20
 */
@Api(tags = " 预约咨询")
@RestController
@RequestMapping("/consulting")
public class PorConsultingController extends BaseController {
    @Autowired
    private IPorConsultingService porConsultingService;

    /**
     * 查询预约咨询列表
     */
    @ApiOperation(value="查询预约咨询列表", notes="查询预约咨询列表")
    @GetMapping("/list")
    public TableDataInfo list(PorConsulting porConsulting) {
        startPage();
        List<PorConsulting> list = porConsultingService.selectPorConsultingList(porConsulting);
        return getDataTable(list);
    }

    /**
     * 导出预约咨询列表
     */
    @ApiOperation(value="导出预约咨询列表", notes="导出预约咨询列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, PorConsulting porConsulting) throws IOException {
        List<PorConsulting> list = porConsultingService.selectPorConsultingList(porConsulting);
        ExcelUtil<PorConsulting> util = new ExcelUtil<PorConsulting>(PorConsulting.class);
        util.exportExcel(response, list, "预约咨询数据");
    }
    /**
     * 获取预约咨询详细信息
     */
    @ApiOperation(value="获取预约咨询详细信息", notes="获取预约咨询详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(porConsultingService.selectPorConsultingById(id));
    }

    /**
     * 新增预约咨询
     */
    @ApiOperation(value="新增预约咨询", notes="新增预约咨询")
    @PostMapping
    public AjaxResult add(@RequestBody PorConsulting porConsulting) {
        return toAjax(porConsultingService.insertPorConsulting(porConsulting));
    }

    /**
     * 修改预约咨询
     */
    @ApiOperation(value="修改预约咨询", notes="修改预约咨询")
    @PutMapping
    public AjaxResult edit(@RequestBody PorConsulting porConsulting) {
        return toAjax(porConsultingService.updatePorConsulting(porConsulting));
    }

    /**
     * 修改预约咨询
     */
    @ApiOperation(value="同步预约咨询", notes="同步预约咨询到客户信息")
    @PutMapping(value="/sync")
    public AjaxResult sync(@RequestBody String id) {
        return porConsultingService.syncPorConsulting(id);
    }

    /**
     * 删除预约咨询
     */
    @ApiOperation(value="删除预约咨询", notes="删除预约咨询")
    @ApiImplicitParam(name = "ids", value = "预约咨询ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(porConsultingService.deletePorConsultingByIds(ids));
    }
}
